package com.jiker.order;

import com.jiker.Area;
import com.jiker.Coordinates;

/**
 * @author leo
 * @date 2021/6/16
 */
public class MoveForward extends Move {
    private final Area area;

    public MoveForward(Area area) {
        super(area);
        this.area = area;
    }

    @Override
    public Coordinates move(Coordinates coordinates) {
        switch (coordinates.getDirection()) {
            case SOUTH:
                coordinates.setY(coordinates.y() - 1);
                break;
            case NORTH:
                coordinates.setY(coordinates.y() + 1);
                break;
            case EAST:
                coordinates.setX(coordinates.x() + 1);
                break;
            case WEST:
                coordinates.setX(coordinates.x() - 1);
                break;
            default:
                break;
        }

        return isOverstep(coordinates);
    }

    public Coordinates isOverstep(Coordinates coordinates) {
        return OverStepHandler.overStepHandler(coordinates, area);
    }
}
